<template>
  <div class="home">
    <h1>定位信息</h1>
    <div>
      <button @click="geLocation">手动获取</button>
      <button @click="triggerShowBackNotify">{{isShow ? "关闭后台定位" : "开启后台定位"}}</button>
    </div>
    {{data}}
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Plugins } from '@capacitor/core';
const { LocationPlugin } = Plugins;

@Component({
  components: {
  },
})
export default class Home extends Vue {

  public data = "";

  public isShow = false;

  public created(){
    LocationPlugin.addListener('onReceiveLocation', (locationObj: any) => {
      this.data = "监听地图定位：\n"+JSON.stringify(locationObj);
    });
  }

  public async geLocation(){
    const value = await LocationPlugin.getLocation({ value: '传递的参数' });
    this.data = "手动获取的定位信息："+JSON.stringify(value);
  }

  public async triggerShowBackNotify(isShow?: boolean){
    const value = LocationPlugin.triggerShowBackNotify({isShow: isShow});
    this.isShow = value;
  }

}
</script>
